package com.ellricky.baselib.ui.visit;


import android.view.View;
import android.widget.AdapterView;

import com.andr.common.http.callback.BaseCallback;
import com.andr.common.ui.adapter.BaseRecyclerAdapter;
import com.andr.common.ui.mvp.BasePresenter;
import com.ellricky.baselib.BaseConstant;
import com.ellricky.baselib.R;
import com.ellricky.baselib.adapter.visit.VisitAdapter;
import com.ellricky.baselib.cache.LocalCacheUtil;
import com.ellricky.baselib.entity.visit.VisitEntity;
import com.ellricky.baselib.http.callback.EListCallback;
import com.ellricky.baselib.ui.base.BaseRefreshActivity;
import com.ellricky.baselib.util.EAppUtil;

import java.util.List;

import static com.ellricky.baselib.http.Api.API_VISIT_LIST;

public class VisitListActivity extends BaseRefreshActivity<Void, BasePresenter<Void>, VisitEntity> {

    private String clueId;

    @Override
    public void initUIView() {
        clueId = getIntent().getStringExtra(BaseConstant.KEY_ID);
        super.initUIView();
        mTvTitle.setText(R.string.base_visit_list);
        if (LocalCacheUtil.isConsultantRole()){
            setRightBtn(0);
        }
    }

    @Override
    protected BaseCallback getResponseCallback() {
        return new EListCallback<VisitEntity>(this) {
            @Override
            protected void onSuccess(List<VisitEntity> data, String msg) {
                dataSource = data;
                rvView.onLoadFinish(dataSource, refresh);
            }

            @Override
            protected void onErrorCode(String code, String msg) {
                super.onErrorCode(code, msg);
                rvView.onRefreshFailed(refresh);
            }

            @Override
            protected void onHttpError(String code, String msg) {
                super.onHttpError(code, msg);
                rvView.onRefreshFailed(refresh);
            }
        };
    }

    @Override
    protected BaseRecyclerAdapter<VisitEntity> getRvAdapter() {
        return new VisitAdapter();
    }

    @Override
    protected void initParamMap() {
        super.initParamMap();
        paramMap.put("backvisitId", clueId);
    }

    @Override
    protected String getUrlPath() {
        return API_VISIT_LIST;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        super.onItemClick(adapterView, view, position, l);
        String visitId = adapter.get(position).getId();
        EAppUtil.jumpPageWithId(this, VisitDetailActivity.class, visitId);
    }

    @Override
    protected void onClickBtnRight() {
        super.onClickBtnRight();
        EAppUtil.jumpPageWithId(this, VisitCreateActivity.class, clueId);
    }

}
